package controllers

import (
	"gcopyright/models"
	"github.com/kataras/iris"
	"log"
)

type Common struct {
	Ctx iris.Context
}

func (c *Common) ReturnJson(status int, message string, args ...interface{}) {
	var array []interface{}
	for _, v := range args {
		array = append(array, v)
	}
	var result = models.CommonReturn{
		Code:    status,
		Message: message,
		Ps:      array,
	}
	c.Ctx.JSON(result)
	c.Ctx.StopExecution()
	return
}

func (c *Common) ReturnSuccess(args ...interface{}) {
	var array []interface{}
	for _, v := range args {
		array = append(array, v)
	}
	var result = models.CommonReturn{
		Code:    10000,
		Message: "success",
		Ps:      array,
	}
	c.Ctx.JSON(result)
	c.Ctx.StopExecution()
	return
}

func (c *Common) ReturnIntData(args ...int) { //返回Int 数据
	var array []int
	for _, v := range args {
		array = append(array, v)
	}
	var result = models.CommonReturnInt{
		Code:    10000,
		Message: "success",
		Ps:      array,
	}
	c.Ctx.JSON(result)
	c.Ctx.StopExecution()
	return
}

func (c *Common) Check(err error) {
	if err != nil {
		log.Fatal("ERROR:    ", err)
	}
}
